ProductDetailView = {
	ctrl: ProductDetailController,
	
	init : function() {
		 var data = this.ctrl.model;
		 $id("detailTitle").setText(data.BookDetail.Name);
		 $id("detailAuthor").setText(data.BookDetail.Author);
		 $id("detailContent").setText(data.BookDetail.Des);
		 $id("detailPrice").setText(data.BookDetail.Price);
		 $id("txtCmt").setAttribute("bookID",data.BookDetail.Id);
		 $id("detailImg").src=data.BookDetail.imageUrl;
		 this.createCommentsNode(data.Comments);
         this.disableAddToCart();         
	},

    disableAddToCart : function() {
        var data = this.ctrl.model;
        var isDisable = CartController.checkItemInCart(data.BookDetail);
        if(isDisable) {
            $id("addToCart").setText("Added this book to your cart");
        } else {
            $id("addToCart").setText("Add to cart");
        }
    },
	
	createCommentsNode : function(arrCmts) {
		var rootNode = $id("users");
		var nodeUser = null;
		var nodeAvatar = null;
		var nodeCmtBox = null;
		var nodeUserName = null;
		var nodeUserLink = null;
		var nodeCmt = null; 
		var nodeTime = null;
		var cmt = null;
		var length = arrCmts.length; 		
 		
 		rootNode.innerHTML = "";
 		
		for(var i=0;i<length;i++) {
			cmt = arrCmts[i];
			
			nodeUser = createDiv();
			nodeUser.addClass("user");
			
			nodeAvatar = createDiv();
			nodeAvatar.addClass("avatar");
			nodeAvatar.style.background = "url(" + cmt.Avatar + ")";
			
			nodeCmtBox = createDiv();
			nodeCmtBox.addClass("contentCmt");
			
			nodeUserName = createDiv();
			nodeUserName.addClass("username");
			
			nodeUserLink = createNode("a");
			nodeUserLink.setText(cmt.UserName);			
			
			nodeCmt = createDiv();
			nodeCmt.addClass("comment");
			nodeCmt.setText(cmt.Comment);
			
			nodeTime = createDiv();
			nodeTime.addClass("time");
			nodeTime.setText(cmt.Time);
			
			nodeUserName.appendChild(nodeUserLink);
			
			nodeCmtBox.appendChild(nodeUserName);
			nodeCmtBox.appendChild(nodeCmt);
			nodeCmtBox.appendChild(nodeTime);
			
			nodeUser.appendChild(nodeAvatar);
			nodeUser.appendChild(nodeCmtBox);
			
			rootNode.appendChild(nodeUser);			
		 }		
	},
	
	updateScrollBar: function() {
		$id("users").scrollTop = $id("users").scrollHeight;
	}
};